import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { EliteTowerFloorData } from "./EliteTowerFloorData";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { FrameTimer } from "../../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { DataEvent } from "../../../events/DataEvent";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
type int = number;
//class EliteTowerFloorButton
    
    export  class EliteTowerFloorButton extends GSprite
    {
        constructor(arg1: int)
        {
            super();
            this._floor = arg1;
            this._bm = new GBitmap();
            this.addChild(this._bm);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddedToStageHandler);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        public updateUrl(): void
        {
            this._bm.bitmapData = GlobalClass.getBitmapData("guildEliteTower_floor" + this._floor);
            return;
        }

        public updateData(arg1: EliteTowerFloorData): void
        {
            this._data = arg1;
            if (this._data.reach) 
            {
                this.addFireEffect();
            }
            else 
            {
                this.removeFireEffect();
            }
            return;
        }

        /* internal  */addFireEffect(): void
        {
            if (!this._fireEffect) 
            {
                this._fireEffect = new SWFPlayer();
                this._fireEffect.sceneX = this.getX(this._floor);
                this._fireEffect.sceneY = this.getY(this._floor);
                this._fireEffect.load("GuildEliteTowerFloorEffect_" + this._floor + ".swf", ModelType.Effect, null);
                this._fireEffect.loadComplete = this.onFireLoadedCompleteHandler;
                this.addChild(this._fireEffect);
            }
            return;
        }

        /* internal  */onFireLoadedCompleteHandler(arg1: SWFPlayer): void
        {
            if (arg1.movieClipData) 
            {
                arg1.movieClipData.isClear(false);
            }
            return;
        }

        /* internal  */getX(arg1: int): int
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case 1:
                {
                    return 82;
                }
                case 2:
                {
                    return 73;
                }
                case 3:
                {
                    return 67;
                }
                case 4:
                {
                    return 65;
                }
                case 5:
                {
                    return 54;
                }
                case 6:
                {
                    return 53;
                }
                case 7:
                {
                    return 43;
                }
            }
            return 0;
        }

        /* internal  */getY(arg1: int): int
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case 1:
                {
                    return 102;
                }
                case 2:
                {
                    return 100;
                }
                case 3:
                {
                    return 86;
                }
                case 4:
                {
                    return 82;
                }
                case 5:
                {
                    return 68;
                }
                case 6:
                {
                    return 67;
                }
                case 7:
                {
                    return 76;
                }
            }
            return 0;
        }

        /* internal  */removeFireEffect(): void
        {
            if (this._fireEffect) 
            {
                this._fireEffect.parent.removeChild(this._fireEffect);
                this._fireEffect.dispose();
                this._fireEffect = null;
            }
            return;
        }

        /* internal  */onAddedToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (!this._frameTimer) 
            {
                this._frameTimer = new FrameTimer(2);
                this._frameTimer.addListener(TimerType.ENTERFRAME, this.onEmterFrameHandler);
            }
            this._frameTimer.start();
            return;
        }

        /* internal  */onEmterFrameHandler(arg1: FrameTimer): void
        {
            if (!this._data || !this._data.reach) 
            {
                this._bm.filters = [FilterConst.colorFilter];
            }
            else if (this._data.selected) 
            {
                this._bm.filters = [FilterConst.yellowGlowFilter];
            }
            else if (this.hoverTest()) 
            {
                this._bm.filters = [FilterConst.yellowGlowFilter];
            }
            else 
            {
                this._bm.filters = [];
            }
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._frameTimer) 
            {
                this._frameTimer.stop();
                this._frameTimer.dispose();
                this._frameTimer = null;
            }
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._data || !this._data.reach) 
            {
                return;
            }
            if (!this.hoverTest()) 
            {
                return;
            }
            if (this._data && !this._data.selected) 
            {
                this._data.selected = true;
                this.dispatchEvent(new DataEvent(GModuleEvent.GuildElite_FloorSelectedChange, this._data, false, true));
            }
            return;
        }

        /* internal  */hoverTest(): Boolean
        {
            if (this._bm.bitmapData == null) 
            {
                return false;
            }
            return this._bm.bitmapData.getPixel32(this._bm.mouseX, this._bm.mouseY) > 0;
        }

        /* internal */ /* var */_frameTimer: FrameTimer;

        /* internal */ /* var */_bm: GBitmap;

        /* internal */ /* var */_floor: int;

        /* internal */ /* var */_fireEffect: SWFPlayer;

        /* internal */ /* var */_data: EliteTowerFloorData;
    }
